package org.moonlight.redis.limit.config;

import org.moonlight.redis.limit.interceptor.AccessLimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器及拦截路径
 * @author Moonlight
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final AccessLimitInterceptor accessLimitInterceptor;

    @Autowired
    public InterceptorConfig(AccessLimitInterceptor interceptor) {
        this.accessLimitInterceptor = interceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessLimitInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login");
    }
}